package com.hspedu.newData.dmsxl.回溯.子集;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author: yh
 * @description:
 * @CreateTime: 2025-05-19
 * @Version: 1.0
 */

//todo
public class LC491非递减子序列 {

    List<List<Integer>> list = new ArrayList<>();
    List<Integer> path = new LinkedList<>();

    public List<List<Integer>> findSubsequences(int[] nums) {
        backtracking(nums,0);
        return list;
    }

    public void backtracking(int[] nums,int startIndex){
        if (path.size()>1){
            list.add(new ArrayList<>(path));
        }
        HashSet<Integer> hs = new HashSet<>();
        for (int i = startIndex; i < nums.length; i++) {
            if(!path.isEmpty() && path.get(path.size() -1 ) > nums[i] || hs.contains(nums[i]))
                continue;
            hs.add(nums[i]);
            path.add(nums[i]);
            backtracking(nums, i + 1);
            path.remove(path.size() - 1);
        }
    }
}
